#include "expextracttimeframe.h"
#include "ui_expextracttimeframe.h"
#include<QDebug>
ExpExtractTimeFrame::ExpExtractTimeFrame(QWidget *parent,Experiment* pExperiment) :
    QFrame(parent),
    ui(new Ui::ExpExtractTimeFrame)
{
    ui->setupUi(this);
    this->pExperiment=pExperiment;

    connect(ui->spinBox_ExpAfter,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_ExpBefore,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));

    connect(ui->spinBox_SampleMin,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_SampleMax,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_SampleStable,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->checkBox_SampleMonitor,SIGNAL(stateChanged(int)),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_SampleCount,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->comboBox_Sample,SIGNAL(currentIndexChanged(int)),this,SIGNAL(SIG_DataChanged()));

    connect(ui->spinBox_WashMin,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_WashMax,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->checkBox_WashMonitor,SIGNAL(stateChanged(int)),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_WashCount,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_WashSpeed,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_WashStable,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));
    connect(ui->comboBox_Wash,SIGNAL(currentIndexChanged(int)),this,SIGNAL(SIG_DataChanged()));

    connect(ui->groupBox_Injector,SIGNAL(clicked(bool)),this,SIGNAL(SIG_DataChanged()));
    connect(ui->spinBox_Injector,SIGNAL(editingFinished()),this,SIGNAL(SIG_DataChanged()));

    connect(this,SIGNAL(SIG_DataChanged()),this,SLOT(OnDataChanged()));

    LoadData();
}

ExpExtractTimeFrame::~ExpExtractTimeFrame()
{
    delete ui;
}

void ExpExtractTimeFrame::LoadData()
{
    pExtractionTime=pExperiment->GetExtractionTimePtr();

    this->blockSignals(true);
    ui->spinBox_ExpBefore->setValue(pExtractionTime->expBefore);
    ui->spinBox_ExpAfter->setValue(pExtractionTime->expAfter);

    ui->spinBox_SampleMin->setValue(pExtractionTime->extractMinDelay);
    ui->spinBox_SampleMax->setValue(pExtractionTime->extractMaxDelay);
    ui->spinBox_SampleStable->setValue(pExtractionTime->extractStabilityTime);
    ui->checkBox_SampleMonitor->setChecked(pExtractionTime->bExtractMonitor);
    ui->spinBox_SampleCount->setValue(pExtractionTime->extractMean);
    ui->comboBox_Sample->setCurrentText(pExtractionTime->extractDelayAction);

    ui->spinBox_WashMin->setValue(pExtractionTime->washMinDelay);
    ui->spinBox_WashMax->setValue(pExtractionTime->washMaxDelay);
    ui->checkBox_WashMonitor->setChecked(pExtractionTime->bWashMonitor);
    ui->spinBox_WashCount->setValue(pExtractionTime->washMean);
    ui->spinBox_WashSpeed->setValue(pExtractionTime->washPumpSpeed);
    ui->spinBox_WashStable->setValue(pExtractionTime->washStabilityTime);
    ui->comboBox_Wash->setCurrentText(pExtractionTime->washDelayAction);

    ui->groupBox_Injector->setChecked(pExtractionTime->bInjectorUsed);
    ui->spinBox_Injector->setValue(pExtractionTime->injectorPumpSpeed);
    this->blockSignals(false);
}

void ExpExtractTimeFrame::OnDataChanged()
{
    pExtractionTime->expBefore=ui->spinBox_ExpBefore->value();
    pExtractionTime->expAfter=ui->spinBox_ExpAfter->value();

    pExtractionTime->extractMinDelay=ui->spinBox_SampleMin->value();
    pExtractionTime->extractMaxDelay=ui->spinBox_SampleMax->value();
    pExtractionTime->extractStabilityTime=ui->spinBox_SampleStable->value();
    pExtractionTime->bExtractMonitor=ui->checkBox_SampleMonitor->isChecked();
    pExtractionTime->extractMean=ui->spinBox_SampleCount->value();
    pExtractionTime->washDelayAction=ui->comboBox_Sample->currentText();

    pExtractionTime->washMinDelay=ui->spinBox_WashMin->value();
    pExtractionTime->washMaxDelay=ui->spinBox_WashMax->value();
    pExtractionTime->bWashMonitor=ui->checkBox_WashMonitor->isChecked();
    pExtractionTime->washMean=ui->spinBox_WashCount->value();
    pExtractionTime->washPumpSpeed=ui->spinBox_WashSpeed->value();
    pExtractionTime->washStabilityTime=ui->spinBox_WashStable->value();
    pExtractionTime->washDelayAction=ui->comboBox_Wash->currentText();

    pExtractionTime->bInjectorUsed=ui->groupBox_Injector->isChecked();
    pExtractionTime->injectorPumpSpeed=ui->spinBox_Injector->value();

    qDebug()<<"ExpExtractTimeFrame::OnDataChanged()";
    //LoadData();
}
